package org.openems.entity;

import java.io.Serializable;

public class Key implements Serializable, Comparable<Key> {
	@Override
	public int hashCode() {
		String tmp = this.application + this.value;
		return tmp.hashCode();
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public String toString() {
		return this.application + ":" + this.value.toString();
	}

	public String getApplication() {
		return application;
	}

	public void setApplication(String application) {
		this.application = application;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -3878150748656707739L;

	@Override
	public boolean equals(Object obj) {
		return ((Key)obj).toString().equals(this.toString());
	}


	private String value;
	private String application;
	
	public Key(String value, String application) {
		this.value = value;
		this.application = application;
	}
	
	public Key() {
		this.value = "";
		this.application = "";
	}

	public static Key createKey(String value, String application) {
		return new Key(value, application);
	}

	public static Key createKey() {
		return new Key();
	}

	public static Key toKey(String s) {
		String[] tmp =  s.split(":");
		return createKey(tmp[1], tmp[0]);
	}

	@Override
	public int compareTo(Key o) {
		if ( this.toString().equals(((Key)o).toString()) ) {
			return 0;
		}
		return 1;
	}

	
}
